<?php 

require "../gobal.php";


function doCreateContact(){

     $realname=$_POST["ClientName"];
     $tel=$_POST["ClientPhone"];
     $address=$_POST["ClientAddress"];
     $addr=$_POST["ClientBulidNo"];
     $lng=$_POST["LocationLng"];
     $lat=$_POST["LocationLat"];
	  
	$customer=currCustomer();
     $customer_id=$customer["id"];
	$sql="INTO `customer_contact`(`realname`, `tel`, `address`, `lng`, `lat`, `customer_id`) VALUES ('$realname','$tel','$address  $addr',0,0,$customer_id)";
	$id=insert_row($sql);
	echo $id;

}

function getContacts(){

	$customer=currCustomer();
	$sql="select * from customer_contact where customer_id=". $customer["id"];
	$contacts=fetch_rows($sql);
	$res="{list:". json_encode($contacts)."}";
	echo $res;
}

function getContact(){
    $id=$_POST["id"];
	$sql="select * from customer_contact where id=$id";
	$contacts=fetch_rows($sql);
	$res="{model:". json_encode($contacts[0])."}";
	echo $res;
} 


function  toWXPayment(){

	session_start();
	$_SESSION["body"]=$_POST["body"];
    $_SESSION["amount"]=$_POST["amount"];
	$_SESSION["attach"]=$_POST["attach"];
	$_SESSION["oid"]=$_POST["oid"];
	$_SESSION["goods_tag"]=$_POST["goods_tag"];
	
	$basePath=getBasePath();
	$url="$basePath/payment/jsapi.php";

	location_to($url);
}


header("Content-type: application/json; charset=utf-8"); 

$action=$_GET["action"] ;



switch($action){

	case "doCreateContact": doCreateContact();break;
	case "getContacts": getContacts();break;
	case "getContact": getContact();break;

	case "toWXPayment": toWXPayment();break;

	default : break;

}


?>